package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/tool"
	"group-card/model/entity"
	"group-card/rpc/card/cardclient"
	"group-card/rpc/card/internal/svc"
)

type PublishUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPublishUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishUpdateLogic {
	return &PublishUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PublishUpdateLogic) PublishUpdate(in *cardclient.PublishUpdateRequest) (*cardclient.PublishUpdateResponse, error) {
	data := entity.CardPublishReq{
		Id:                 in.Id,
		PublishTime:        tool.StringToTime(in.PublishTime),
		AdminId:            in.AdminId,
		CustomerId:         in.CustomerId,
		SkinId:             in.SkinId,
		Count:              in.Count,
		BeginNumber:        in.BeginNumber,
		EndNumber:          in.EndNumber,
		Status:             in.Status,
		Type:               in.Type,
		ServiceNumber:      in.ServiceNumber,
		ServiceOrderNumber: in.ServiceOrderNumber,
		ServiceMoney:       in.ServiceMoney,
	}

	var ctx context.Context
	err := l.svcCtx.PublishModel.Update(ctx, &data)

	if err != nil {
		return nil, err
	}

	return &cardclient.PublishUpdateResponse{}, nil
}
